/***************************************************************************
 *
 * A wrap to the native syscall functions 
 *
 **************************************************************************/
#ifndef SYSCALL_H
#define SYSCALL_H

#include "common.h"
#include "crossbit/UTIL.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
//getrlimit,setrlimit,getusage
#include <sys/time.h>
//times
#include <sys/times.h>
#include <sys/resource.h>
//uname
#include <sys/utsname.h>
//ioctl
#include <sys/ioctl.h>
#include <fcntl.h>
//time
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
//error_no
#include <errno.h>
//assert
#include <assert.h>
//signal
#include <signal.h>

namespace crossbit
{

    class SYSCALL{

        public:
            static XTMemAddr sys_brk;
            static XTMemAddr original_brk;
            static XTMemAddr sys_mmap;

        public:

            static XTInt32 XTOpen(const XTPStr pathname, XTInt32 flags);
            static XTInt32 XTOpen(const XTPStr pathname, XTInt32 flags, mode_t mode);
            static XTInt32 XTClose(XTInt32 fd);
            static XTInt32 XTFork(void);
            static XTInt32 XTExecve(const XTPStr filename , XTPStr * argv , XTPStr * envp);

            static XTInt32 XTRead(XTInt32 fd, void *buf, XTInt32 count);
            static XTInt32 XTWrite(XTInt32 fd, void *buf, XTInt32 count);

            static XTInt32 XTIoctl(XTInt32 d, XTInt32 request, ...);
            static XTInt32 XTFcntl(XTInt32 fd, XTInt32 cmd, XTInt64 arg);

            static XTUint32 XTGetuid();
            static XTUint32 XTGetgid();
            static XTUint32 XTGeteuid();
            static XTUint32 XTGetegid();

            static XTUint32 XTGetpid();
            static XTUint32 XTTime(time_t *t);
            static XTUint32 XTTimes(struct tms *buf);

            static XTInt32 XTGetrlimit(XTInt32 resource, struct rlimit *rlim);
            static XTInt32 XTSetrlimit(XTInt32 resource, const struct rlimit *rlim);
            static XTInt32 XTGetrusage(XTInt32 who, struct rusage *usage);
            static XTInt32 XTUname(struct utsname *buf);
            static XTInt32 XTRename(XTPStr oldpath, XTPStr newpath);
            static XTInt32 XTUnlink(XTPStr pathname);
            static XTInt32 XTReadlink(const XTPStr path, XTPStr buf, XTUint32 bufsiz);

            static void XTExit(XTInt32 status);

            static XTInt32 XTLseek(XTInt32 fd, XTInt32 offset, XTInt32 whence);
            static XTInt32 XTStat(const XTPStr file_name, struct stat *buf);
            static XTInt32 XTFstat(XTInt32 filedes, struct stat *buf);

            static void *XTMmap(void *start, XTUint32 length, XTInt32 prot, XTInt32 flags, XTInt32 fd, XTInt32 offset);
            static void *XTMremap(void *old_address, XTUint32 old_size, XTUint32 new_size, XTUint32 flags);

            static XTInt32 XTMunmap(void *start, XTUint32 length);

            static XTInt32 XTBrk(void *end_data_segment);

            static XTInt32 XTSigaction(XTInt32 signum, const struct sigaction *act, struct sigaction *oldact);
			static XTInt32 XTSigfillset(sigset_t *sig_set);
			static XTInt32 XTSigemptyset(sigset_t *sig_set);
			static XTInt32 XTSigpending(sigset_t *sig_set);
			static XTInt32 XTSigprocmask(XTInt32 how, const sigset_t *sig_set,sigset_t *sig_oldset);


    };

}

#endif
